﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GaduBot
{
    enum LogTypes
    {
        Fatal = 1,
        Error,
        Warn,
        Info,
        Debug
    }
    class Logger
    {
        private System.Windows.Forms.RichTextBox console;
        private GaduBot.Properties.Settings AppSets = new GaduBot.Properties.Settings();
        private bool IsInitialized = false;
        private int LogLevel = (int)LogTypes.Info;

        public Logger(System.Windows.Forms.RichTextBox textbox)
        {
            if (!this.IsInitialized)
            {
                this.Initialize(textbox);
            }
        }
        ~Logger()
        {

        }
        private void Initialize(System.Windows.Forms.RichTextBox Ttextbox)
        {
            this.console = Ttextbox;
            IsInitialized = true;
        }
        public void Destroy()
        {

        }
        public void Log(LogTypes LogType, string LogMsg)
        {
            if ((int)LogType <= (int)LogLevel)
            {
                string LogText = "";
                string LogTypeStr = "";
                switch ((LogTypes)LogType)
                {
                    case LogTypes.Fatal:
                        LogTypeStr = "FATAL";
                        break;
                    case LogTypes.Error:
                        LogTypeStr = "ERROR";
                        break;
                    case LogTypes.Warn:
                        LogTypeStr = "WARN";
                        break;
                    case LogTypes.Info:
                        LogTypeStr = "INFO";
                        break;
                    case LogTypes.Debug:
                        LogTypeStr = "DEBUG";
                        break;
                    default:
                        break;
                }
                LogText = System.DateTime.Now.ToShortTimeString() + "[" + LogTypeStr + "]" + "\"" + LogMsg + "\"\n";
                System.IO.StreamWriter LogFile = System.IO.File.AppendText("GaduBot.log");
                LogFile.Write(LogText);

                console.AppendText(LogText);

                LogFile.Close();
            }
        }
    }
}
